<!-- 新增或修改地址 -->
<template>
  <div>
    <van-area @confirm="confirmChooseAddress" title="标题" :area-list="areaList" />
    <van-button type="danger" @click="saveAddress">保存</van-button>
  </div>
</template>

<script>
import { areaList } from '@vant/area-data';
import {
  saveAction as saveActionApi
} from '@/api/address'
export default {
  name:'AddressDetail',
  data () {
    return {
        areaList ,
        chooseAddress:[],
        addressId:''
    }
  },

  components: {},

  computed: {},

  created() {
    this.addressId = this.$route.query.addressId
    if(this.addressId){ // 修改地址
      // 发请求获取 地址详情
    }
  },

  mounted() {},

  methods: {
    confirmChooseAddress(e){
        console.log(e);
        this.chooseAddress = e
    },
    async saveAddress(){
        // 新增和修改都是这同一个接口
        let res = await saveActionApi({
          address:this.chooseAddress.map(item=>item.name).join(' '),
          // 新增地址，直接传空字符串，修改时传具体的地址id
          addressId:'',
          checked:false,
          detailadress:'黄泉路-奈何桥-56号',
          openId:localStorage.getItem('openId'),
          telNumber:'13588880909',
          userName:'李四'
        })
    }
  }
}

</script>
<style lang='scss' scoped>
</style>